<template>
  <div class="app-container home">
    <el-row :gutter="20">
      <el-col :sm="24" :lg="24">
      </el-col>
    </el-row>
    <el-row :gutter="20">
      <el-col :sm="24" :lg="12" style="padding-left: 20px">
        <h2>药品管理系统</h2>
        <p>
          药品管理系统
        </p>
      </el-col>

    </el-row>
    <el-divider />
    <el-row :gutter="20">
      <el-col :xs="24" :sm="24" :md="12" :lg="12">
        <el-card class="update-log" style="height: 350px">
          <template v-slot:header>
            <div class="clearfix">
              <span>联系信息</span>
            </div>
          </template>
          <div class="body" id="chart1" style="height: 300px">

          </div>
        </el-card>
      </el-col>
<!--      <el-col :xs="24" :sm="24" :md="12" :lg="8">-->
<!--        <el-card class="update-log" style="height: 350px">-->
<!--          <template v-slot:header>-->
<!--            <div class="clearfix">-->
<!--              <span>联系信息</span>-->
<!--            </div>-->
<!--          </template>-->
<!--          <div class="body" style="height:300px;">-->
<!--            <h1>供应商数量：{{providers.length}}</h1>-->
<!--          </div>-->
<!--        </el-card>-->
<!--      </el-col>-->
      <el-col :xs="24" :sm="24" :md="12" :lg="12">
        <el-card class="update-log" style="height: 350px">
          <template v-slot:header>
            <div class="clearfix">
              <span>销售统计</span>
            </div>
          </template>
          <div class="body" id="chart3" style="height: 300px">

          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup name="Index">
import * as echarts from 'echarts'
import {listDrug} from "@/api/system/drug.js";
import {listProvider} from "@/api/system/provider.js";
import {listSale} from "@/api/system/sale.js";


const drugs = ref([]);
const providers = ref([]);
const sales = ref([]);
onMounted(() => {
  let res1 = listDrug().then(response => {
    drugs.value = response.rows;
  });
  let res2 = listProvider().then(response => {
    providers.value = response.rows;
  });
  let res3 = listSale().then(response => {
    sales.value = response.rows;
  });
  const res = Promise.all([res1, res2,res3]);
  res.then(()=>{
    let chart1 = echarts.init(document.getElementById('chart1'));
    let option1 = {
      title:{
        text:'药品数量统计',
      },
      tooltip: {},
      legend: {
        data:['数量']
      },
      xAxis: {
        data: drugs.value.map(item => item.drugName)
      },
      yAxis: {},
      series: [{
        name: '数量',
        type: 'bar',
        data: drugs.value.map(item => item.store)
      }]
    }
    chart1.setOption(option1);

    let chart3 = echarts.init(document.getElementById('chart3'));
    let option3 = {
      title:{
        text:'销售统计',
      },
      tooltip: {},
      legend: {
        data:['数量']
      },
      xAxis: {
        data: sales.value.map(item => item.createdTime)
      },
      yAxis: {},
      series: [{
        name: '金额',
        type: 'bar',
        data: sales.value.map(item => item.number * item.price)
      }]
    }
    chart3.setOption(option3);
  })

});

function goTarget(url) {
  window.open(url, '__blank')
}
</script>

<style scoped lang="scss">
.home {
  blockquote {
    padding: 10px 20px;
    margin: 0 0 20px;
    font-size: 17.5px;
    border-left: 5px solid #eee;
  }
  hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
  }
  .col-item {
    margin-bottom: 20px;
  }

  ul {
    padding: 0;
    margin: 0;
  }

  font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: #676a6c;
  overflow-x: hidden;

  ul {
    list-style-type: none;
  }

  h4 {
    margin-top: 0px;
  }

  h2 {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 100;
  }

  p {
    margin-top: 10px;

    b {
      font-weight: 700;
    }
  }

  .update-log {
    ol {
      display: block;
      list-style-type: decimal;
      margin-block-start: 1em;
      margin-block-end: 1em;
      margin-inline-start: 0;
      margin-inline-end: 0;
      padding-inline-start: 40px;
    }
  }
}
</style>

